#include <stdio.h>
#include <math.h>

// Get a load of led pins matriex
int leftLedMatriex[] = { 3, 5 };    // left led
int middleLedPin = 6;               // middle light
int rightLedMatriex[] = { 10, 9 };  // right led

int index = 0;

int a = 0;

// init pins
void setup() {
  int ledPinsMatriexSize = 2;
  for (int i = 0; i < ledPinsMatriexSize; i++) {
    pinMode(leftLedMatriex[i], OUTPUT);
    pinMode(rightLedMatriex[i], OUTPUT);
  }
  pinMode(middleLedPin, OUTPUT);
}

// loop function，left led up，right led down
// When the light is at the middle, the light will light from the middle to the boundary.
// At first, the light will light from the boundary to the middle.
void loop() {
  analogWrite(middleLedPin, a);
  a += 10;
  if (a >= 255)
    a = 0;

  // left
  analogWrite(leftLedMatriex[index], 255);
  // right
  analogWrite(rightLedMatriex[index], 255);
  delay(300);
  analogWrite(leftLedMatriex[index], 0);
  // right
  analogWrite(rightLedMatriex[index], 0);
  // limit the index range.
  if (index)
    index = 0;
  else
    index = 1;
}
